<?php

/**
 * This is the model class for table "hs_order".
 *
 * The followings are the available columns in table 'hs_order':
 * @property integer $id
 * @property string $order_no
 * @property integer $room_id
 * @property string $price
 * @property string $submit_time
 * @property integer $status
 * @property string $in_date
 * @property string $out_date
 * @property integer $order_type
 * @property integer $bed_type
 * @property string $remark
 * @property string $other
 * @property string $pay_time
 * @property integer $pay_type
 * @property integer $user_id
 * @property string $room_name
 * @property integer $room_count
 * @property integer $add_bed
 * @property integer $r_msg
 * @property integer $r_email
 * @property string $link_name
 * @property integer $link_gender
 * @property string $link_mobile
 * @property string $link_id_card
 * @property string $link_address
 * @property string $link_email
 * @property string $link_desc
 *
 * The followings are the available model relations:
 * @property User $user
 */
class Order extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Order the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'hs_order';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('order_no, room_id, price, submit_time, status, in_date, out_date, order_type, bed_type, user_id, room_name', 'required'),
			array('room_id, status, order_type, bed_type, pay_type, user_id, room_count, add_bed, r_msg, r_email, link_gender', 'numerical', 'integerOnly'=>true),
			array('order_no', 'length', 'max'=>24),
			array('price', 'length', 'max'=>12),
			array('remark, other', 'length', 'max'=>512),
			array('room_name', 'length', 'max'=>256),
			array('link_name, link_mobile, link_id_card', 'length', 'max'=>32),
			array('link_address', 'length', 'max'=>128),
			array('link_email', 'length', 'max'=>64),
			array('link_desc', 'length', 'max'=>1024),
			array('pay_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, order_no, room_id, price, submit_time, status, in_date, out_date, order_type, bed_type, remark, other, pay_time, pay_type, user_id, room_name, room_count, add_bed, r_msg, r_email, link_name, link_gender, link_mobile, link_id_card, link_address, link_email, link_desc', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'user' => array(self::BELONGS_TO, 'User', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'order_no' => 'Order No',
			'room_id' => 'Room',
			'price' => 'Price',
			'submit_time' => 'Submit Time',
			'status' => 'Status',
			'in_date' => 'In Date',
			'out_date' => 'Out Date',
			'order_type' => 'Order Type',
			'bed_type' => 'Bed Type',
			'remark' => 'Remark',
			'other' => 'Other',
			'pay_time' => 'Pay Time',
			'pay_type' => 'Pay Type',
			'user_id' => 'User',
			'room_name' => 'Room Name',
			'room_count' => 'Room Count',
			'add_bed' => 'Add Bed',
			'r_msg' => 'R Msg',
			'r_email' => 'R Email',
			'link_name' => 'Link Name',
			'link_gender' => 'Link Gender',
			'link_mobile' => 'Link Mobile',
			'link_id_card' => 'Link Id Card',
			'link_address' => 'Link Address',
			'link_email' => 'Link Email',
			'link_desc' => 'Link Desc',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('order_no',$this->order_no,true);
		$criteria->compare('room_id',$this->room_id);
		$criteria->compare('price',$this->price,true);
		$criteria->compare('submit_time',$this->submit_time,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('in_date',$this->in_date,true);
		$criteria->compare('out_date',$this->out_date,true);
		$criteria->compare('order_type',$this->order_type);
		$criteria->compare('bed_type',$this->bed_type);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('other',$this->other,true);
		$criteria->compare('pay_time',$this->pay_time,true);
		$criteria->compare('pay_type',$this->pay_type);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('room_name',$this->room_name,true);
		$criteria->compare('room_count',$this->room_count);
		$criteria->compare('add_bed',$this->add_bed);
		$criteria->compare('r_msg',$this->r_msg);
		$criteria->compare('r_email',$this->r_email);
		$criteria->compare('link_name',$this->link_name,true);
		$criteria->compare('link_gender',$this->link_gender);
		$criteria->compare('link_mobile',$this->link_mobile,true);
		$criteria->compare('link_id_card',$this->link_id_card,true);
		$criteria->compare('link_address',$this->link_address,true);
		$criteria->compare('link_email',$this->link_email,true);
		$criteria->compare('link_desc',$this->link_desc,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}